//-----------------------------------------------------------------------
//<copyright file="ChiTietPhieuXuatDAO.cs
//Code generate by tools.
//</copyright>
//-----------------------------------------------------------------------

using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using PMS.Exceptions;
using System.Data.SqlClient;
using PMS.Entity;

namespace PMS.DAL
{
	public class ChiTietPhieuXuatDAO : SQLDatabase, IChiTietPhieuXuatDAO
	{

		#region Create ChiTietPhieuXuat methods

		public ChiTietPhieuXuat CreateChiTietPhieuXuat(ChiTietPhieuXuat chiTietPhieuXuat)
		{
			try
			{

				SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietPhieuXuatInsert");
				AddInParameter(command, "@MaCTPX", SqlDbType.NVarChar, chiTietPhieuXuat.MaCTPX);
				AddInParameter(command, "@DonGia", SqlDbType.Int, chiTietPhieuXuat.DonGia);
				AddInParameter(command, "@SoLuong", SqlDbType.Int, chiTietPhieuXuat.SoLuong);
				AddInParameter(command, "@GiaTrungThau", SqlDbType.Int, chiTietPhieuXuat.GiaTrungThau);
				AddInParameter(command, "@SoPX", SqlDbType.NVarChar, chiTietPhieuXuat.SoPX);
                AddInParameter(command, "@MaLuuKho", SqlDbType.Int, chiTietPhieuXuat.MaLuuKho);

				ExecuteNonQuery(command);
				return chiTietPhieuXuat;
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access CreateChiTietPhieuXuatException", ex);
			}
		}

		#endregion

		#region Update ChiTietPhieuXuat methods

		public void UpdateChiTietPhieuXuat(ChiTietPhieuXuat chiTietPhieuXuat)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietPhieuXuatUpdate");

				AddInParameter(command, "@MaCTPX", SqlDbType.NVarChar, chiTietPhieuXuat.MaCTPX);
				AddInParameter(command, "@DonGia", SqlDbType.Int, chiTietPhieuXuat.DonGia);
				AddInParameter(command, "@SoLuong", SqlDbType.Int, chiTietPhieuXuat.SoLuong);
				AddInParameter(command, "@GiaTrungThau", SqlDbType.Int, chiTietPhieuXuat.GiaTrungThau);
				AddInParameter(command, "@SoPX", SqlDbType.NVarChar, chiTietPhieuXuat.SoPX);
                AddInParameter(command, "@MaLuuKho", SqlDbType.NVarChar, chiTietPhieuXuat.MaLuuKho);

				ExecuteNonQuery(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access UpdateChiTietPhieuXuatException", ex);
			}
		}

		#endregion

		#region Delete ChiTietPhieuXuat methods

		public void DeleteChiTietPhieuXuat(ChiTietPhieuXuat chiTietPhieuXuat)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietPhieuXuatDelete");

				AddInParameter(command, "@MaCTPX", SqlDbType.NVarChar, chiTietPhieuXuat.MaCTPX);

				ExecuteNonQuery(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access DeleteChiTietPhieuXuatException", ex);
			}
		}

        public void DeleteChiTietPhieuXuatBySoPX(string SoPX)
        {
            try
            {
                SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietPhieuXuatDeleteAllBySoPX");

                AddInParameter(command, "@SoPX", SqlDbType.NVarChar, SoPX);

                ExecuteNonQuery(command);
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access DeleteChiTietPhieuXuatException", ex);
            }
        }

		#endregion

		#region Select methods

		#region GetAll ChiTietPhieuXuat methods

		public ChiTietPhieuXuats GetAllChiTietPhieuXuat()
		{
			try
			{

				SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietPhieuXuatGetList");
				ChiTietPhieuXuats Result = new ChiTietPhieuXuats();
				List<ChiTietPhieuXuat> List = ExecuteQuery<ChiTietPhieuXuat>(command,true);
				foreach(ChiTietPhieuXuat item in List)
				{
					Result.Add(item);
				}
				return Result;
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access GetAllChiTietPhieuXuatException", ex);
			}
		}

        public ChiTietPhieuXuats GetAllChiTietPhieuXuatBySoPX(string SoPX)
        {
            try
            {

                SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietPhieuXuatSelectAllBySoPX");
                AddInParameter(command, "@SoPX", SqlDbType.NVarChar, SoPX);
                ChiTietPhieuXuats Result = new ChiTietPhieuXuats();
                List<ChiTietPhieuXuat> List = ExecuteQuery<ChiTietPhieuXuat>(command, true);
                foreach (ChiTietPhieuXuat item in List)
                {
                    Result.Add(item);
                }
                return Result;
            }
            catch (Exception ex)
            {
                throw DataAccessException.GetException("Data Access GetAllChiTietPhieuXuatException", ex);
            }
        }
		#endregion


		#region GetChiTietPhieuXuat methods

		public ChiTietPhieuXuat GetChiTietPhieuXuatByID(string maCTPX)
		{
			try
			{
				SqlCommand command = SQLDatabase.StoredProcedureCommand("spChiTietPhieuXuatGet");

				AddInParameter(command, "@maCTPX", SqlDbType.NVarChar, maCTPX);

				return ExecuteQuery<ChiTietPhieuXuat>(command);
			}
			catch (Exception ex)
			{
				throw DataAccessException.GetException("Data Access GetChiTietPhieuXuatBy ID Exception", ex);
			}
		}

		#endregion


		#endregion
	}
}//End Class
